{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenges 1: Reading Error Messages\n",
    "\n",
    "Read the traceback below, and identify the following pieces of information about it:\n",
    "\n",
    "1.  How many levels does the traceback have?\n",
    "2.  What is the file name where the error occurred?\n",
    "3.  What is the function name where the error occurred?\n",
    "4.  On which line number in this function did the error occurr?\n",
    "5.  What is the type of error?\n",
    "6.  What is the error message?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'errors_02'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-2b0d766dbc9a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0merrors_02\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0merrors_02\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprint_friday_message\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'errors_02'"
     ]
    }
   ],
   "source": [
    "import errors_02\n",
    "errors_02.print_friday_message()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many levels does the traceback have?\n",
    "<br>1\n",
    "\n",
    "What is the file name where the error occurred?\n",
    "<br>errors_02\n",
    "\n",
    "On which line number in this function did the error occurr?\n",
    "<br>1\n",
    "\n",
    "What is the type of error?\n",
    "<br>ImportError\n",
    "\n",
    "What is the error message?\n",
    "<br>No module named 'errors_02'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 2. Identifying Syntax Errors\n",
    "\n",
    "1. Read the code below, and (without running it) try to identify what the errors are.\n",
    "2. Run the code, and read the error message. Is it a `SyntaxError` or an `IndentationError`?\n",
    "3. Fix the error.\n",
    "4. Repeat steps 2 and 3, until you have fixed all the errors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def another_function():\n",
    "    print(\"Syntax errors are annoying.\")\n",
    "    print(\"But at least python tells us about them!\")\n",
    "    print(\"So they are usually not too hard to fix.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`SyntaxError`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Syntax errors are annoying.\n",
      "But at least python tells us about them!\n",
      "So they are usually not too hard to fix.\n"
     ]
    }
   ],
   "source": [
    "another_function()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 3. Identifying Variable Name Errors\n",
    "\n",
    "1. Read the code below, and (without running it) try to identify what the errors are.\n",
    "2. Run the code, and read the error message. What type of `NameError` do you think this is? In other words, is it a [string](https://github.com/dlab-berkeley/python-intensive/blob/master/Glossary.md#string) with no quotes, a misspelled variable, or a variable that should have been defined but was not?\n",
    "3. Fix the error.\n",
    "4. Repeat steps 2 and 3, until you have fixed all the errors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abbabbabba\n"
     ]
    }
   ],
   "source": [
    "message = \"\"\n",
    "for number in range(10):\n",
    "    # use a if the number is a multiple of 3, otherwise use b\n",
    "    if (number % 3) == 0:\n",
    "        message = message + \"a\"\n",
    "    else:\n",
    "        message = message + \"b\"\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Number is not defined because Number != number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 4. Identifying Item Errors\n",
    "\n",
    "1. Read the code below, and (without running it) try to identify what the errors are.\n",
    "2. Run the code, and read the error message. What type of error is it?\n",
    "3. Fix the error."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My favorite season is  Winter\n"
     ]
    }
   ],
   "source": [
    "seasons = ['Spring', 'Summer', 'Fall', 'Winter']\n",
    "print('My favorite season is ', seasons[3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python starts index at 0!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
